import React, {useContext, useEffect, useState} from 'react';
import {StatusBar, ImageBackground, View, TextInput, Dimensions, Alert} from 'react-native';
import { Button, Image, Text } from 'react-native-elements';

import LocaleContext from '../libs/locale';
import AsyncStorage from "@react-native-async-storage/async-storage";
import WalletContext from "../libs/wallet";
import {TouchableHighlight} from "react-native-gesture-handler";
import Toast from "react-native-simple-toast";
import {constansts} from "../libs/constansts";
import {bytes2Hex, keyPairFromSeed, randomSeed, toAddress} from "../libs/keyPair";
import {convertKeyPair} from "../libs/ed2curve";
import {enAES, joinGroup} from "../libs/chatGroup";

const {width,height,scale} = Dimensions.get("window");

const ChatGroupRemark = ({ navigation,route }: any) => {
    const locale:any = useContext(LocaleContext);
    const wallet: any = useContext(WalletContext);

    const[ChatGroupName,setChatGroupName] = useState("")

    const modifyRemark = async () => {
        let ChatGroupList = await AsyncStorage.getItem("myChatGroupList") || "[]";
        // console.log("主页数据："+SaveList)
        let resList: any = JSON.parse(ChatGroupList) || [];
        console.log(ChatGroupList)
        for(let i = 0 ; i < resList.length ; i++)
        {
            if(resList[i].addressOut == route?.params?.Q_Address)
            {
                resList[i].selfRemark = ChatGroupName;
                await AsyncStorage.setItem("myChatGroupList",JSON.stringify(resList))
                Toast.show("修改成功");
                navigation.goBack();
                break;
            }
            if(i == (resList.length - 1))
            {
                Alert.alert("","修改失败");
                return ;
            }
        }
    }

    return (
        <>
            <TextInput
                // underlineColorAndroid={"black"}
                // errorMessage={}

                // value={ChatNum}
                onChangeText={async (value) => {
                    // console.log(value)
                    setChatGroupName(value);
                    if(value == "")
                    {
                        Toast.show("请输入群备注")
                        return ;
                    }
                    console.log("1")
                }}
                placeholder={"请输入群名称"}

                style={{marginTop:5,fontSize: 20,height:50,width:width,padding:0,paddingLeft:width*0.05,borderBottomWidth:1,borderBottomColor:"#F3F3F3",color:"black",fontWeight:"bold"}}
            />
            <TouchableHighlight
                underlayColor={"#98FB98"}
                style={{margin:25,padding:25,backgroundColor:"#00FF00"}}
                onPress={async () => {
                    await modifyRemark();
                }}>
                <Text>修改备注</Text>
            </TouchableHighlight>

        </>
    );
};

export default ChatGroupRemark;
